// JavaScript Document
function setPic(pic,width,height,alt,classname){
	pic =  decode64(pic);
	writestr = "<img src='"+pic+"' ";
	if(width>0){
		writestr+=" width="+width;
	}
	if(height>0){
		writestr+=" height="+height;
	}
	writestr = writestr+" title='"+alt+"' class='"+classname+"' />";
	document.write(writestr);
}

function getpic(thispic,pic){
	
	pic =  decode64(pic);
	thispic.src = pic;
}
function tihuan()
{
	str = decode64(str);
	document.getElementById("tb_content").innerHTML = str;

}
function clickurl(urlid){
	urlid =  decode64(urlid);
	window.open(urlid);
	//location.href=urlid;
	
}

function checkLogin(session){//session为1记录登陆状态
    var ddusername=$('#loginuser').val();
	var dduserpwd=$('#loginpwd').val();
	var jump_href=$('#jump_href').attr('href');
	if(ddusername=='' || dduserpwd==''){
	    alert('用户名或密码不能为空');
	}
	else{
	    $.post('ajax.php?fun=checkLogin', {'ddusername':ddusername,'dduserpwd':dduserpwd,'session':session}, function(data){
		    if(data>0){
				//$('.jumpbox').hide();
				//location.replace(location.href);
			    window.location.href=jump_href;
		    }
			else{
			    alert('账号密码错误');
			}
	    });
	}
}

function parse_url(url){
 var pattern = /(\w+)=(\w+)/ig;
 var parames = {};
 url.replace(pattern, function(a, b, c){
  parames[b] = c;
 });
 return parames;
}

function AddFavorite(sURL, sTitle){
 try{
  window.external.addFavorite(sURL, sTitle);
  }
 catch (e){
  try{
   window.sidebar.addPanel(sTitle, sURL, "");
   }
  catch (e)
  {
   alert("加入收藏失败，您的浏览器不允许，请使用Ctrl+D进行添加");
  }
 }
}

function searchForm(){
    var _url = $("#s-txt").val();
	$('#s-txt').val(_url.replace('-',' '));
	$('#s-txt').val(_url.replace('/',' '));
	var regExp = /(.*\.?taobao.com(\/|$))|(.*\.?tmall.com(\/|$))/i;
	if (_url.match(regExp)){
		var parames = parse_url(_url);
		if (typeof(parames) == 'object'){
			var iid=parames['id'];
			if(iid==null || iid=="undefined"){
			    var iid=parames['item_num_id'];
				if(iid==null || iid=="undefined"){
				    var iid=parames['default_item_id'];
					if(iid==null || iid=="undefined"){
				        var iid=parames['item_id'];
						if(iid==null || iid=="undefined"){
				            var iid=parames['itemId'];
							if(iid==null || iid=="undefined"){
				                var iid=parames['mallstItemId'];
				            }
				        }
				    }
				}
			}
			$('#s-txt').val(iid);
		    $('#s-txt').attr('name','iid');
			$('.box').attr('action',$('#shangpin').attr('s'));
		}
		return true;
	}
}


$(function(){
	$('.s-nav a').click(function(){
		$('.s-nav a').removeClass().addClass('n');
		$(this).removeClass().addClass('y');
		$('#s-txt').val($(this).attr('value'));
		$('#s-txt').attr('name',$(this).attr('name'));
		$('.box').attr('action',$(this).attr('s'));
	});
});

function inArray(val,array){
	for(var i in array){
	    if(array[i]==val){
		    return val;
		}
	}
	return '';
}